package com.powernode.controller;

import com.github.pagehelper.PageInfo;
import com.powernode.domain.Activity;
import com.powernode.model.R;
import com.powernode.query.ActivityQueryCondition;
import com.powernode.service.ActivityService;
import com.powernode.vo.ActivityDetailInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 市场活动接口管理
 */
@RestController
@RequestMapping("/api/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 条件分页查询市场活动列表
     * @param activityQueryCondition
     * @return
     */
    @GetMapping("/page")
    public R<PageInfo<ActivityDetailInfoVo>> loadActivityPage(ActivityQueryCondition activityQueryCondition) {
        PageInfo<ActivityDetailInfoVo> pageInfo = activityService.queryActivityListByPage(activityQueryCondition);
        return R.OK(pageInfo);
    }

    /**
     * 新增市场活动
     * @param activity
     * @return
     */
    @PostMapping
    public R<String> saveActivity(@RequestBody Activity activity) {
        Boolean saved = activityService.saveActivity(activity);
        return R.HANDLER(saved);
    }

    /**
     * 查询市场活动信息
     * @param activityId
     * @return
     */
    @GetMapping("/info/{activityId}")
    public R<Activity> loadActivityInfo(@PathVariable Integer activityId) {
        Activity activity = activityService.queryActivityById(activityId);
        return R.OK(activity);
    }

    /**
     * 修改市场活动信息
     * @param activity
     * @return
     */
    @PutMapping
    public R<String> modifyActivity(@RequestBody Activity activity) {
        Boolean modified = activityService.modifyActivity(activity);
        return R.HANDLER(modified);
    }

    /**
     * 根据标识查询市场活动详情
     * @param activityId
     * @return
     */
    @GetMapping("/detail/info/{activityId}")
    public R<ActivityDetailInfoVo> loadActivityDetailInfo(@PathVariable Integer activityId) {
        ActivityDetailInfoVo activityDetailInfoVo = activityService.queryActivityDetailInfoById(activityId);
        return R.OK(activityDetailInfoVo);
    }

    /**
     * 查询所有市场活动列表
     * @return
     */
    @GetMapping("/list")
    public R<List<Activity>> loadAllActivityList() {
        List<Activity> list = activityService.queryAllActivityList();
        return R.OK(list);
    }
}
